package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.SelectBean;

public class ShangpinListServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public ShangpinListServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SelectBean sb = new SelectBean();
		String sql = "select * from shangpin";
		String sql1 = "select * from leibie";
		String sql2 = "select * from souyin";
		String sql3 = "select * from supplier";
		String sql4 = "select * from dingdan";
		String [] args = {"id","name","candi","jinjia","danjia","danwei","zhonglei","kucun","supplierid"};
		String [] args1 = {"id","leibie"};
		String [] args2 = {"id","souru","jine","souyinyuan","soutime"};
		String [] args3 = {"id","name","addrss","lianxi"};
		String [] args4 = {"id","supplierid","zuangtai","times"};
		ArrayList al = sb.select(sql, args);
		ArrayList al1 = sb.select(sql1, args1);
		ArrayList al2 = sb.select(sql2, args2);
		ArrayList al3 = sb.select(sql3, args3);
		ArrayList al4 = sb.select(sql4, args4);
		request.setAttribute("shangpin", al);
		request.setAttribute("leibie", al1);
		request.setAttribute("souyin", al2);
		request.setAttribute("supplier", al3);
		request.setAttribute("dingdan", al4);
		
		String sql5 = "select count(zhonglei) as sums,zhonglei from shangpin group by zhonglei";
		String[] args5 = {"sums","zhonglei"};
		ArrayList al5 = sb.select(sql5, args5);
		request.setAttribute("tongji", al5);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
